package com.ttjj.entity.map;

import com.alibaba.fastjson.annotation.JSONField;
import com.ttjj.common.Constants;
import com.ttjj.enums.EnumBlockType;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * 地图元素封装
 */
@Data
@EqualsAndHashCode
public class MapElement {
    @JSONField(
        ordinal = 1
    )
    protected int x;
    @JSONField(
        ordinal = 2
    )
    protected int y;
    @JSONField(
        ordinal = 3
    )
    protected EnumBlockType type;

    public MapElement() {
    }

    public MapElement(int x, int y, EnumBlockType type) {
        this.x = x;
        this.y = y;
        this.type = type;
    }

    public Position toPosition() {
        return new Position(this.y / 50, this.x / 50);
    }

    @JSONField(
        serialize = false
    )
    public List<Position> getHousePosSet() {
        List<Position> result = new ArrayList();
        int len = Constants.getCommonLen();
        Coordinate cod = new Coordinate(this.x, this.y);
        result.add(cod.getTopLeftCod(len).toPosition());
        result.add(cod.getTopRightCod(len).toPosition());
        result.add(cod.getDownLeftCod(len).toPosition());
        result.add(cod.getDownRightCod(len).toPosition());
        return result;
    }
}
